var e = require;
var t = module;
var o = exports;
var n;
Object.defineProperty(o, "__esModule", {value: !0}), (o.CoinBoxType = void 0);
var r,
    s = e("SDK"),
    c = e("AdUtils"),
    l = e("TreasureChestBox");
(function (e) {
    (e[(e.CONVENTION = 1)] = "CONVENTION"), (e[(e.BIG = 2)] = "BIG"), (e[(e.TWINS = 3)] = "TWINS");
})((r = o.CoinBoxType || (o.CoinBoxType = {})));
var d = cc._decorator,
    u = d.ccclass,
    p = d.property,
    h = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.tryNode = null),
                (t.randomCoin = null),
                (t.boxList = []),
                (t.coinLableList = []),
                (t.coinNodeList = []),
                (t.videoCallBack = null),
                (t.closeCallBack = null),
                (t.isClick = [!1, !1, !1, !1, !1]),
                (t.itemIndex = null),
                (t._coin = 0),
                (t.boxType = r.BIG),
                t
            );
        }
        return (
            __extends(t, e),
            (t.prototype.onLoad = function () {}),
            (t.prototype.onEnable = function () {
                s.default.Instance.showBanner(),
                    (this.isClick = [!1, !1, !1, !1, !1]),
                    (this.randomCoin.active = !1),
                    (this.tryNode.active = !0);
                var e = cc.director.getScene().getChildByName("Canvas");
                if (s.default.Instance.isPortrait()) {
                    if (e.width >= 720) return;
                    this.node.getChildByName("bg_bx").scale = e.width / 720;
                } else {
                    if (e.height > 750) return;
                    (this.node.getChildByName("bg_bx").scale = e.height / 720),
                        this.node.getChildByName("bg_bx").scale < 1 && (this.node.getChildByName("bg_bx").scale -= 0.1);
                }
            }),
            (t.prototype.start = function () {}),
            (t.prototype.showView = function (e, t, o, n, i) {
                if (
                    (void 0 === o && (o = null),
                    void 0 === n && (n = null),
                    (this.videoCallBack = t),
                    (this.closeCallBack = o),
                    (this.boxType = i),
                    n)
                )
                    if ((e = n.type) == l.TreasureBox.COIN) {
                        var a = n.coin;
                        this.setUIData(a);
                    } else if (e == l.TreasureBox.DIAMONDS) {
                        var r = n.diamonds;
                        this.setUIData(r);
                    } else if (e == l.TreasureBox.RADOM) {
                        var s = c.default.instance.getRandomInt(1, 2);
                        s == l.TreasureBox.COIN
                            ? ((a = n.coin), this.setUIData(a))
                            : s == l.TreasureBox.DIAMONDS && ((r = n.diamonds), this.setUIData(r));
                    }
            }),
            (t.prototype.setUIData = function (e) {
                this.boxdata = e;
                for (var t = 0; t < this.coinNodeList.length; t++)
                    for (var o = this.coinNodeList[t], n = o.children, i = 0; i < o.children.length; i++)
                        "icon_coin" == n[i].name && this.setImg(n[i], e);
                this._coin = c.default.instance.getRandomInt(e.min, e.max);
            }),
            (t.prototype.setImg = function (e, t) {
                c.default.instance.loadPrefabs(t.res, function (t) {
                    (e.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t)), (e.scale = 0.8);
                });
            }),
            (t.prototype.onGetCoin = function (e, t) {
                if (((this.itemIndex = t), !this.isClick[t])) {
                    var o = this;
                    s.default.Instance.showRewardVideo(
                        function () {
                            o.videoAwardCallback(), s.default.Instance.showToast("获得奖励");
                        },
                        function () {
                            s.default.Instance.showToast("观看广告失败");
                        },
                        function () {
                            s.default.Instance.showToast("暂无广告");
                        }
                    );
                }
            }),
            (t.prototype.onGetRandomCoin = function () {
                var e = Math.floor(5 * Math.random()),
                    t = this;
                (this.itemIndex = e),
                    s.default.Instance.showRewardVideo(
                        function () {
                            t.videoAwardCallback(), s.default.Instance.showToast("获得奖励");
                        },
                        function () {
                            s.default.Instance.showToast("观看广告失败");
                        },
                        function () {
                            s.default.Instance.showToast("暂无广告");
                        }
                    );
            }),
            (t.prototype.onClose = function () {
                var e = this;
                (this.node.parent = null),
                    this.boxType == r.BIG
                        ? s.default.Instance.showGetUICoinBox(
                              function (t) {
                                  e.videoCallBack(t);
                              },
                              function () {
                                  e.closeCallBack();
                              },
                              s.default.Instance.gameID,
                              2,
                              r.TWINS
                          )
                        : (s.default.Instance.hideBanner(), this.closeCallBack());
            }),
            (t.prototype.videoAwardCallback = function () {
                var e = this;
                console.log("customEventData:", this.itemIndex),
                    5 == this.itemIndex && ((this.tryNode.active = !1), (this.randomCoin.active = !0)),
                    (this.isClick[this.itemIndex] = !0),
                    this.itemIndex > this.boxList.length && (this.itemIndex = 0),
                    this.boxList[this.itemIndex].getComponent(sp.Skeleton).setAnimation(0, "open_first", !1),
                    this.boxList[this.itemIndex].getComponent(sp.Skeleton).setCompleteListener(function () {
                        e.coinNodeList[e.itemIndex].active ||
                            (cc.log("设置动画一次播放完成后的事件"),
                            (e.coinNodeList[e.itemIndex].active = !0),
                            (e._coin = c.default.instance.getRandomInt(e.boxdata.min, e.boxdata.max)),
                            (e.coinLableList[e.itemIndex].string = e._coin + ""),
                            console.log("获得多少icon：", e.coinLableList[e.itemIndex]),
                            console.log("获得多少icon：", e.coinLableList),
                            console.log("获得多少icon：", e.coinNodeList[e.itemIndex].parent.name),
                            e.videoCallBack(e._coin));
                    });
            }),
            __decorate([p(cc.Node)], t.prototype, "tryNode", void 0),
            __decorate([p(cc.Node)], t.prototype, "randomCoin", void 0),
            __decorate([p(cc.Node)], t.prototype, "boxList", void 0),
            __decorate([p(cc.Label)], t.prototype, "coinLableList", void 0),
            __decorate([p(cc.Node)], t.prototype, "coinNodeList", void 0),
            __decorate([u], t)
        );
    })(cc.Component);
o.default = h;
